#include "widgetui.h"
#include "ui_widgetui.h"
#include <QKeyEvent>
#include <QMouseEvent>
#include <QDebug>
#include <QPainter>
WidgetUi::WidgetUi(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::WidgetUi)
{
    ui->setupUi(this);
    ui->lineEdit->installEventFilter(this);
    ui->lineEdit->clearFocus();
    this->setFocus();
}

WidgetUi::~WidgetUi()
{
    delete ui;
}

bool WidgetUi::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == ui->lineEdit) {
        if (event->type() == QEvent::MouseButtonDblClick) {
            ui->lineEdit->setProperty("checkedStat","checked");
            qDebug()<<"1111";
            qDebug()<<styleSheet();
            setStyleSheet(styleSheet());
            return  true;
        }
        else if (event->type() == QEvent::MouseButtonPress) {
            qDebug()<<"2222";
            ui->lineEdit->setProperty("checkedStat","unchecked");
            setStyleSheet(styleSheet());
            ui->lineEdit->clearFocus();
            this->setFocus();
            return  true;
        }
        else if (event->type() == QEvent::Leave) {
            qDebug()<<"2222111";
            ui->lineEdit->setProperty("checkedStat","unchecked");
            setStyleSheet(styleSheet());
            ui->lineEdit->clearFocus();
            this->setFocus();
            return  true;
        }else if (event->type() == QEvent::KeyPress) {
            QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
            if (keyEvent->key() == Qt::Key_Return ||
                    keyEvent->key() == Qt::Key_Enter ||
                    keyEvent->key() == Qt::Key_Escape) {
                 qDebug()<<"3333";
                 ui->lineEdit->setProperty("checkedStat","unchecked");
                 setStyleSheet(styleSheet());
                 ui->lineEdit->clearFocus();
                 this->setFocus();
                 return  true;
            }
        }

    }
    return QWidget::eventFilter(watched,event);
}

